import time
import page
from base.base import Base


class PageLogin(Base):

    # 点击登录链接
    def page_click_login_link(self):
        self.base_click_element(page.login_link)

    # 输入账号
    def page_input_username(self, username):
        self.base_in_element_input(page.login_username, username)

    # 输入密码
    def page_input_password(self, password):
        self.base_in_element_input(page.login_password, password)

    # 输入验证码
    def page_input_verify(self, verify):
        self.base_in_element_input(page.login_verify, verify)

    # 点击登录按钮
    def page_click_login_btn(self):
        self.base_click_element(page.login_btn)

    # 获得异常信息
    def page_get_error_text(self):
        error_text = self.base_get_element_text(page.login_error_text)
        return error_text

    # 获取验证码图片
    def page_get_verify_img(self):
        verify_img = self.base_get_element_img(page.login_verify_img)
        return verify_img

    # 获得截屏
    def page_get_screenshot(self):
        self.base_get_img()

    # 在验证码图片上悬浮
    def page_cover_verify_img(self):
        self.base_move_to_element(page.login_verify_img)

    # 悬浮在登录按钮上
    def page_cover_login_btn(self):
        self.base_move_to_element(page.login_btn)

    # 点击更换验证码
    def page_click_verify_img(self):
        self.base_click_element(page.login_update_verify)

    # 点击退出链接
    def page_click_logout_link(self):
        self.base_click_element(page.login_logout_link)

    # 判断是否登录成功
    def page_login_is_or_not_success(self):
        try:
            self.base_find_element(page.login_logout_link)
            return True
        except:
            return False

    # 判断是否退出成功
    def page_logout_is_or_not_success(self):
        try:
            self.base_find_element(page.login_link)
            return True
        except:
            return False

    # 刷新页面
    def page_refresh(self):
        self.base_refresh()

    # 组合登录操作
    def page_login(self, username, password, verify):
        self.page_input_username(username)
        time.sleep(1)
        self.page_input_password(password)
        time.sleep(1)
        self.page_input_verify(verify)
        time.sleep(1)
        self.page_click_login_btn()
